#include<16f877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include"lcd.h"
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#BYTE RCREG = 0x1A           //Receive char
unsigned char i=0,card_id[11];

#INT_RDA
void SerialDataReceive()
{
	card_id[i]=RCREG;		// Store the received data byte by byte
	i++;
}

void buzzer(unsigned char loop, int tone)
{
   unsigned char beep;
   for(beep=0;beep<loop;beep++)
   {
      output_high(PIN_B0);
      delay_ms(tone);
      output_low(PIN_B0);
      delay_ms(tone);
   }
}

void main()
{
unsigned char value=5,ii=0;

Lcd_init();
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
port_b_pullups(true);

buzzer(3,500);

LCD_Clear();
row1();
   display("ENTER UR ID");
   
LCD_Clear();
row1();
   display("YOUR CART VALUE");
row2();
if(input(PIN_B1) == 0)
{
   value=0x39;
   display("1000");
}
else
{
   value=0x35;
   display("500");
}
      delay_ms(2500);

LCD_Clear();
row1();
   display("SHOPPING CART");
   while(1)
	{
		ii=0;
		while(ii<11); //12
		row2();
		ii=0;

      if(card_id[10]==0x34)
      {
        // value=value-1;
         if(value>0)
         {
           // display(value);
            display("500");
      delay_ms(2000);
         }
         else
         {
            display("LIMIT CROSSED");
            buzzer(5,50);
      delay_ms(2500);
         }
         card_id[10]=0;
      }

      if(card_id[10]==0x35)
      {
      if(value==0x31)
      {
      value=0x30;
      }
      else
      {
         value=value-2;
      }
         if(value>0x30)
         {
            display(val[value]);
            display("00");
      delay_ms(200);
         }
         else
         {
            display("LIMIT CROSSED");
            buzzer(5,50);
      delay_ms(2500);
         }
         card_id[10]=0;
      }
       // display(card_id[10]);
	}
}
/*

#include<16f877a.h>
//#include<string.h>
//#include<stdio.h>
//#include<input.c>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
//#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#BYTE RCREG = 0x1A           //Receive char

unsigned char str[11],i;
unsigned char card_id[12];
//unsigned char data[]="Unique ID No.";
//unsigned char a[]={"0012813964"};

//unsigned char b[]={"0012813965"};

#INT_RDA
void SerialDataReceive()
{
	card_id[i]=RCREG;		// Store the received data byte by byte
	i++;
}

void buzzer(unsigned char loop, int tone)
{
   unsigned char beep;
   for(beep=0;beep<loop;beep++)
   {
      output_high(PIN_C5);
      delay_ms(tone);
      output_low(PIN_C5);
      delay_ms(tone);
   }
}
void cmd(char r)
{
      output_e (0x00);
      output_d (r);
      output_e (0x02);
      delay_us (100);
      output_e (0x00);
      delay_ms (100);
}
void init_lcd()
{
   unsigned char x[] ={ 0x38,0x0E,0x01,0x06,0x02};

   unsigned char i;

   for( i = 0 ; i < 5 ; i++ )
   {
   cmd(x[i]);
   }
}

void display(unsigned int s)
{
   output_e (0x01);
   output_d (s);
   output_e (0x03);
   delay_ms (20);
   output_e (0x01);
   delay_ms (100);
}

void main()
{
char a=5;
 init_lcd ();
// printf("rfid");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
      buzzer(3,500);

  // while(data[i]!='\0')
//	{
//		display(data[i]);	// To send characters one by one from 'data' array
//		i++;
      //delay_ms(1000);
//	}
   display("SHOPPING KART");
   while(1)
	{
		i=0;
		while(i<12);
		cmd(0xC0);
		i=0;
	/*	while(i<11)
		{
			display(card_id[i]);	// Print the 12 byte received data
			i++;
       //  delay_ms(1000);
		}/

      if(card_id[11]==4)
      {
      a-=1;
      if(a!=0)
      {
      display(a);
      display("00");
      }
      else
      {
      display("LIMIT CROSSED");
      buzzer(5,50);
      }
      }

      if(card_id[11]==0x35)
      {
      a-=2;
      if(a<=0)
      {
      display(a);
      display("00");
      }
      else
      {
      display("LIMIT CROSSED");
      buzzer(5,50);
      }
      }

      display(card_id[11]);
     // cmd(0x01);
	}
}
*/
